class GuestNamesController < ApplicationController
  before_action :set_guest_name, only: [:show, :edit, :update, :destroy]

  # GET /guest_names
  # GET /guest_names.json
  def index
    @guest_names = GuestName.all

    @guest_names_all = "["

    @guest_names.each{|name|

      @guest_names_all  = @guest_names_all + "'" + name.real_name + "',"

    }

    p @guest_names_all = @guest_names_all + "]"

    render :layout => false

  end

  # GET /guest_names/1
  # GET /guest_names/1.json
  def show
  end

  # GET /guest_names/new
  def new
    @guest_name = GuestName.new
  end

  # GET /guest_names/1/edit
  def edit
  end

  # POST /guest_names
  # POST /guest_names.json
  def create
    @guest_name = GuestName.new(guest_name_params)

    respond_to do |format|
      if @guest_name.save
        format.html { redirect_to @guest_name, notice: 'Guest name was successfully created.' }
        format.json { render action: 'show', status: :created, location: @guest_name }
      else
        format.html { render action: 'new' }
        format.json { render json: @guest_name.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /guest_names/1
  # PATCH/PUT /guest_names/1.json
  def update
    respond_to do |format|
      if @guest_name.update(guest_name_params)
        format.html { redirect_to @guest_name, notice: 'Guest name was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: 'edit' }
        format.json { render json: @guest_name.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /guest_names/1
  # DELETE /guest_names/1.json
  def destroy
    @guest_name.destroy
    respond_to do |format|
      format.html { redirect_to guest_names_url }
      format.json { head :no_content }
    end
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_guest_name
      @guest_name = GuestName.find(params[:id])
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def guest_name_params
      params.require(:guest_name).permit(:from_user_name, :real_name)
    end
end
